package com.casic.modules.sys.controller;

import java.util.List;
import java.util.Map;
import com.casic.common.utils.R;
import com.casic.common.base.entity.PageEntity;
import com.casic.modules.sys.entity.VO.SysDicVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.casic.modules.sys.entity.SysDicEntity;
import com.casic.modules.sys.service.SysDicService;


/**
 * 系统字典表
 * 
 * @author Li
 * @email 123456789@qq.com
 * @date 2019-06-18 11:44:15
 */
@RestController
@RequestMapping("sysdic")
public class SysDicController {
	@Autowired
	private SysDicService sysDicService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sysdic:list")
	public R list(@RequestParam Map<String, Object> params){
        PageEntity<SysDicEntity> page=sysDicService.findPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sysdic:info")
	public R info(@PathVariable("id") String id){
		SysDicEntity sysDic = sysDicService.findById(id);
		return R.ok().put("sysDic", sysDic);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sysdic:save")
	public R save(@RequestBody SysDicEntity sysDic){
		sysDicService.save(sysDic);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sysdic:update")
	public R update(@RequestBody SysDicEntity sysDic){
		sysDicService.edit(sysDic);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sysdic:delete")
	public R delete(@RequestBody String[] ids){
		sysDicService.removeByIds(ids);
		return R.ok();
	}

	/**
	 * 根据民族编码或名称模糊查询民族信息
	 * @param name 民族编码或名称
	 * @return 民族信息的集合
	 */
	@RequestMapping("/findMz")
	@ResponseBody
	public R findMz(@RequestParam(value = "name", required = false) String name) {
		List<SysDicVO> mz = sysDicService.findMz(name);
		return R.ok().put("data", mz);
	}

	/**
	 * 根据行政区划或行政区模糊查询行政区信息
	 * @param name 行政区划或行政区
	 * @return 行政区信息
	 */
	@RequestMapping("/findXzqh")
	@ResponseBody
	public R findXzqh(@RequestParam(value = "name", required = false) String name) {
		List<SysDicVO> xzqh = sysDicService.findXzqh(name);
		return R.ok().put("data", xzqh);
	}
	
}
